function handleErr(msg, url, line_no)
{
    errorMsg = "Error: " + msg + "\n";
    errorMsg += "URL: " + url + "\n";
    errorMsg += "Line: " + line_no + "\n\n";
    alert(errorMsg);
    return true; // It will not show error in browser JavaScript console.
}
onerror = handleErr; // Function handleErr();


var selectedOptions = [];
function countSelected (select){
    maxNumber=5;
    maxNumber=document.getElementById('player_avalible').value;
    var i_message=0;
    for(var i=0; i<select.options.length; i++){
        if(select.options[i].selected && !new RegExp(i,'g').test(selectedOptions.toString())){
            selectedOptions.push(i);
        }

        if(!select.options[i].selected && new RegExp(i,'g').test(selectedOptions.toString())){
            selectedOptions = selectedOptions.sort(function(a,b){
                return a-b
                });
            for(var j=0; j<selectedOptions.length; j++){
                if(selectedOptions[j] == i){
                    selectedOptions.splice(j,1);
                }
            }
        }

        if(selectedOptions.length > maxNumber){
            if(i_message==0){
                alert('You just only choose '+maxNumber+' players!!');
                i_message++;
            }
            select.options[i].selected = false;
            selectedOptions.pop();
            document.body.focus();
        }
    }
}

function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function() {
            oldonload();
            func();
        }
    }
}

function prepareInputsForHints() {
    var inputs = document.getElementsByTagName("input");
    for (var i=0; i<inputs.length; i++){
        // test to see if the hint span exists first
        if (inputs[i].parentNode.getElementsByTagName("span")[0]) {
            // the span exists!  on focus, show the hint
            inputs[i].onfocus = function () {
                this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
            }
            // when the cursor moves away from the field, hide the hint
            inputs[i].onblur = function () {
                this.parentNode.getElementsByTagName("span")[0].style.display = "none";
            }
        }
    }
    // repeat the same tests as above for selects
    var selects = document.getElementsByTagName("select");
    for (var k=0; k<selects.length; k++){
        if (selects[k].parentNode.getElementsByTagName("span")[0]) {
            selects[k].onfocus = function () {
                this.parentNode.getElementsByTagName("span")[0].style.display = "inline";
            }
            selects[k].onblur = function () {
                this.parentNode.getElementsByTagName("span")[0].style.display = "none";
            }
        }
    }
}

//------------------------------------------------- On Change Course ------------------------------------------------\\

function goSearchByIDValue(value){
    keyword = value;
    document.getElementById('keyword').value = keyword;
    goSearch();
}

function goSearch(){
    i = document.getElementById('category_id').selectedIndex;
    // alert(i);
    var id="option"+(i-1);
    // alert(id);
    var a="";
    if(document.getElementById(id))
        a=document.getElementById(id).getAttribute("a");
    if(a!="")
    {
        submitSearch();
    }
}
function submitSearch(){
    document.getElementById('formCourse').submit();
}
//------------------------------------------------ End Change Course ------------------------------------------------//


////////////////////////////////////////////////////////////////////////////////
function add(x,y)
{
    if (y.options.length >= 5 )
    {
        alert('You may only add 5 players!!');
        return	false;
    }//if (y.options.length < 5 )
    else {
        for (var i = 0; i < x.options.length; i++){
            if (x.options[ i ].selected)
            {
                if (y.options.length < 5 ) {
                    try
                    {
                        var a= x.options[ i ];
                        y.add(a,null); // standards compliant
                        i--;
                    }
                    catch(ex)
                    {
                        var a= x.options[ i ];
                        y.add(a); // IE only
                    }
                }
                else{
                    alert('You may only add 5 players!!');
                    return false;
                }
            }
        }
    }
    for (var i = 0; i < y.options.length; i++){
        y.options[ i ].selected="selected";
    }
    return true;
}
////////////////////////////////////////////////////////////////////////////////
function remove(y,x){
    for (var i = 0; i < x.options.length; i++){
        if (x.options[ i ].selected){
            try{
                var a= x.options[ i ];
                y.add(a,null); // standards compliant
                i--;
            }
            catch(ex){
                var a= x.options[ i ];
                y.add(a); // IE only
            }
        }
    }
    for (var i = 0; i < x.options.length; i++){
        x.options[ i ].selected="selected";
    }
}

<!--//////////////////////////////////////////////////////////////////////////////// -->
function search(txt,ob){
    var temp=0;
    var data="";
    for (var i = 0; i < ob.options.length; i++)
        ob.options[ i ].selected="";
    for (var i = 0; i < ob.options.length; i++)
    {
        var text=ob.options[ i ].text.toLowerCase();
        if(txt.value!="")
        {
            if (text.indexOf(txt.value.toLowerCase())>=0)
            {
                if(text.indexOf(txt.value.toLowerCase())==0){
                    temp=i;
                    data=text;
                    break;
                }
                else{
                    if(temp<text.indexOf(txt.value.toLowerCase()))
                    {
                        temp=i;
                        data=text;
                    }
                }
            }
        }
    }
    //document.getElementById('lbl').innerHTML=data;
    if(data=="")
        ob.options[ temp ].selected="";
    else
        ob.options[ temp ].selected="selected";
}





function ValidateForm(form,admin_perm){
    //alert("123");
    ErrorText= "";
    if ( form.player.options.length == 0 ) {
        alert ( "Please add player(s)" );
        return false;
    }
    //if (ErrorText= "") { form.submit() }

    var y=document.getElementById("player");
    for (var i = 0; i < y.options.length; i++){
        y.options[ i ].selected="selected";
    }

    i=0;
    if(admin_perm=="1"){
        $("#player option").each (
            function () {
                // this object is the current option HTML object.
                if(stristr(this.value, '(*)')){
                    i=1;
                }
            }
        );
        if(i==0){
            alert ( "Please Select a Payer" );
            return false;
        }
    }

    // var otherplayer=document.getElementById("cld_otherplayer").value;
    // player_list=otherplayer.split(",");
    //alert(player_list);
    //num_otherplayer=0;
    //if(player_list!="")
    //num_otherplayer=player_list.length;

    if(y.options.length>5){
        alert("You may only add 5 players!!");
        return false;
    }
    return true;

}

function listbox_move(listID, direction) {

    var listbox = document.getElementById(listID);
    var selIndex = listbox.selectedIndex;

    if(-1 == selIndex) {
        alert("Please select an option to move.");
        return;
    }

    var increment = -1;
    if(direction == 'up')
        increment = -1;
    else
        increment = 1;

    if((selIndex + increment) < 0 ||
        (selIndex + increment) > (listbox.options.length-1)) {
        return;
    }

    var selValue = listbox.options[selIndex].value;
    var selText = listbox.options[selIndex].text;
    listbox.options[selIndex].value = listbox.options[selIndex + increment].value
    listbox.options[selIndex].text = listbox.options[selIndex + increment].text

    listbox.options[selIndex + increment].value = selValue;
    listbox.options[selIndex + increment].text = selText;

    listbox.selectedIndex = selIndex + increment;
}
<!--////////////////////////////////Player//////////////////////////////////////////////// -->
<!--//////////////////////////////////////////////////////////////////////////////// -->
function listbox_moveacross(sourceID, destID)
{
    var src = document.getElementById(sourceID);
    var dest = document.getElementById(destID);
    if(dest.options.length>=5 && dest.id=="player")
    {
        alert('You may only add 5 players!!');
        return	false;
    }
    else
    {
        for(var count=0; count < src.options.length; count++)
        {

            if(src.options[count].selected == true)
            {
                var option = src.options[count];
                var newOption = document.createElement("option");
                newOption.value = option.value;
                newOption.text = option.text;
                newOption.selected = true;
                if (dest.options.length < 5  || dest.id=="numbers") {
                    try {
                        dest.add(newOption, null); //Standard
                        src.remove(count, null);
                    }
                    catch(error)
                    {
                        dest.add(newOption); // IE only

                        src.remove(count);
                    }
                    count--;
                }
                else{
                    alert('You may only add 5 players!!');
                    return false;
                }
            }
        }

		remove_mark_payer("numbers");
    }
    return true;
}
<!--//////////////////////////////////////////////////////////////////////////////// -->
function listbox_moveacross_otherplayer(sourceID, destID)
{
    //alert('You may only add 5 players!!');
    var src = document.getElementById(sourceID);
    var dest = document.getElementById(destID);
    if(dest.options.length>=5 && dest.id=="player")
    {
        alert('You may only add 5 players!!');
        return	false;
    }
    else
    {
        for(var count=0; count < src.options.length; count++)
        {

            //	if(src.options[count].selected == true)
            if(src.options[count].selected == true)
            {
                var option = src.options[count];
                var newOption = document.createElement("option");
                newOption.value = option.value;
                newOption.text = option.text;
                newOption.selected = true;
                if (dest.options.length < 5  || dest.id=="ls")
                {
                    try
                    {
                        dest.add(newOption, null); //Standard

                        src.remove(count, null);
                    }
                    catch(error)
                    {
                        dest.add(newOption); // IE only

                        src.remove(count);
                    }
                    count--;
                }
                else{
                    alert('You may only add 5 players!!');
                    return false;
                }
            }
        }
    }
    return true;
}

function listbox_selectall(listID, isSelect) {

    var listbox = document.getElementById(listID);
    for(var count=0; count < listbox.options.length; count++) {

        listbox.options[count].selected = isSelect;

    }
}

function Showpopup(event,time,product_item_price,teetime_begin,teetime_end,product_id,player_avalible)
{
    //	x = event.clientX + document.body.scrollLeft - 35;
    //	y = event.clientY + document.body.scrollTop +15;
    x = document.body.scrollLeft + 200;
    y = document.body.scrollTop +100;
    Popup_fast.style.display="block";
    Popup_fast.style.left = x;
    Popup_fast.style.top = y;
    document.getElementById('interval').value=time;
    document.getElementById('interval_text').value=time;
    document.getElementById('input_time_pop').value=time;
    // alert(teetime_end);
    document.getElementById('price').value=	product_item_price;
    document.getElementById('teetime_end').value= teetime_end;
    document.getElementById('teetime_begin').value= teetime_begin;
    document.getElementById('product_id').value= product_id;
    document.getElementById('player_avalible').value= player_avalible;
}
function Hidepopup()
{
    Popup_fast.style.display="none";
}

function otherPlayerAdd() {
    //var formObject = document.testForm
    var formObject = document.testForm
    if(formObject.player.options.length<5){
        if (formObject.FN_1.value!="" && formObject.LN_1.value!="") {
            addOption(formObject.player,formObject.FN_1,formObject.LN_1)
        }
    }
    if(formObject.player.options.length<5){
        if (formObject.FN_2!="" && formObject.LN_2!="") {
            addOption(formObject.player,formObject.FN_2,formObject.LN_2)
        }
    }
    if(formObject.player.options.length<5){
        if (formObject.FN_3!="" && formObject.LN_3!="") {
            addOption(formObject.player,formObject.FN_3,formObject.LN_3)
        }
    }
    if(formObject.player.options.length<5){
        if (formObject.FN_4!="" && formObject.LN_4!="") {
            addOption(formObject.player,formObject.FN_4,formObject.LN_4)
        }
    }
    if(formObject.player.options.length<5){
        if (formObject.FN_5!="" && formObject.LN_5!="") {
            addOption(formObject.player,formObject.FN_5,formObject.LN_5)
        }
    }
}

//add option
function addOption(selectObject,FN,LN) {
    if((FN.value!="" && LN.value=="")||(FN.value=="" && LN.value!="")){
        alert("Warnning: First Name or Last Name is empty!!!");
        return false;
    }else{
//        alert(FN);
//        alert(FN.value);
//        alert(LN.value);
        if(trim(FN.value)!="" && trim(LN.value)!="" && trim(FN.value)!=" " && trim(LN.value)!=" "){
            var optionObject = new Option(FN.value +", "+ LN.value,"[guest]_"+FN.value+"_"+LN.value);
            var optionRank = selectObject.options.length;
            selectObject.options[optionRank]=optionObject;
            optionObject.selected = true;
            FN.value="";
            LN.value="";
        }else{
            return false;
        }
    }
    return true;
}

function otherPlayerRemove() {
    removeOption()
}

//reomove option
function removeOption() {
    
    $('#player :selected').each(function(i, selected){
        var name= explode(", ",$(selected).text());
        j=i+1;
        while($("#FN_"+j).val()!=""){
            j++;
        }
        $("#FN_"+j).val(name[0]);
        $("#LN_"+j).val(name[1]);
        $(selected).remove();
    });
    return true;
}

function selectPlayer(){
    $("#removeortherplayer").attr("style","visibility: hidden;");
    $('#player :selected').each(function(i, selected){
        if(!stristr($(selected).val(),"[guest]")){
            $("#removeortherplayer").attr("style","visibility: hidden;");
            return false;
        }
        $("#removeortherplayer").attr("style","visibility: visible;");
    });
}

//clear after add
function Clear()
{
    var formObject = document.testForm
    formObject.FN_1.value=""
    formObject.LN_1.value=""
    formObject.FN_2.value=""
    formObject.LN_2.value=""
    formObject.FN_3.value=""
    formObject.LN_3.value=""
    formObject.FN_4.value=""
    formObject.LN_4.value=""
    formObject.FN_5.value=""
    formObject.LN_5.value=""
}
function remove()
{
    var formObject = document.testForm
}
function count_cld(){
    //	var formObject = document.testForm
    document.getElementById("teetime_goldfer").value= document.getElementById("player").length;
    document.getElementById("quantity").value= document.getElementById("player").length;
}
function deleteRecord(url){
    if (confirm('Are you sure you want to delete this record(s)?\nThis operation cannot be undone.'))
        document.location.href=url;
}


/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function comeToTimeCalendar(chour, cminute, first_hour, first_minute, last_hour, last_minute, interval ){
    var time = new Date()
    var hour=time.getHours();
    var minute=time.getMinutes();
    if(hour<first_hour){
        //        return "left";
        return true;
    }
    else if(hour==first_hour && minute<=first_minute){
        //        return "left";
        return true;
    }
    else if(hour>last_hour){
        //        return "right";
        return true;
    }
    else if(hour==last_hour && minute>=last_minute){
        //        return "right";
        return true;
    }
    else{
        if(hour==chour){
            if(minute>=cminute && minute<=(cminute+interval*3)){
                //                return "middle";
                return true;
            }
        }
    }
    //    return "";
    return false;
}

function setPayer(){
//    var player=$("#player").val();
//    var player_text=$("#player :selected").text();
    var i=0;

	remove_mark_payer("player");

    $('#player :selected').each(function(i, selected){
//        foo[i] = $(selected).text();
        if(i==0){
            $(selected).text("(*)" + $(selected).text());
            $(selected).val("(*)" + $(selected).val());
            i++;
        }
    });

//    if(i==1){
//        $("#player :selected").text("(*)" + $("#player :selected").text());
//        $("#player :selected").val("(*)" +$("#player :selected").val());
//    }
//    alert(player);
}

function set_change_payer(){
    setPayer();
}

function remove_mark_payer(list){
	$("#"+list+" option").each (
        function () {
        // this object is the current option HTML object.
            if(stristr(this.value, '(*)')){
//                alert(this.value);
                this.value = substr(this.value, 3);
                this.text = substr(this.text, 3);
//                alert(this.value);
            }
        }
    );
}

function order_status(chk1,chk2){
    $("#"+chk1).attr('checked',false);
    $("#"+chk2).attr('checked',false);
}